#include "CTimeProgress.h"

CTimeProgress::CTimeProgress(void)
{
}

CTimeProgress::~CTimeProgress(void)
{
}
CTimeProgress::CTimeProgress(DWORD dwStyle,wstring strCaption, const CRect &rc, UINT nID)
:	CProgress(dwStyle,strCaption, rc, nID)
{
	Init();
}

void CTimeProgress::Paint(CDC* pDC)
{

	if(m_rcControl.IsRectEmpty())
	{
		return ;
	}

	if(!IsVisible())
	{
		return;
	}

	//PaintBackGnd(pDC); //leon comment for progress flicking 09-05-12

	CDC dcMem;
	dcMem.CreateCompatibleDC(pDC->m_hDC);

	HBITMAP pbmTmp;
	// Draw channel
	if( m_bChannel ) 
	{
		pbmTmp = dcMem.SelectBitmap( m_bmChannel.m_hBitmap );
		// There is a bitmap for active channel
		if( m_bChannelActive) 
		{
			// Vertical slider
			if( m_bVertical ) 
			{
				// Lower part
				DrawBitmap( pDC, m_rcControl.left, m_rcControl.top+Pos2Pixel(m_nPos),
					m_nWidth, m_nHeight - Pos2Pixel(m_nPos),
					&dcMem, 0, Pos2Pixel(m_nPos)
					);

				dcMem.SelectBitmap(m_bmChannelActive.m_hBitmap);
				// Upper part
				DrawBitmap(pDC,m_rcControl.left,m_rcControl.top,m_nWidth,Pos2Pixel(m_nPos),&dcMem, 0, 0);
			}
			else // Horizontal slider
			{
				// Right side
				DrawBitmap(pDC, m_rcControl.left+Pos2Pixel(m_nPos),m_rcControl.top,
					m_nWidth - Pos2Pixel(m_nPos), m_nHeight,
					&dcMem, Pos2Pixel(m_nPos), 0
					);

				dcMem.SelectBitmap( m_bmChannelActive.m_hBitmap );
				// Left side
				DrawBitmap(pDC, m_rcControl.left, m_rcControl.top, Pos2Pixel(m_nPos), m_nHeight,&dcMem, 0, 0);
			
			   dcMem.SelectBitmap( m_bmChannel.m_hBitmap );
               DrawBitmap(pDC, m_rcControl.left, m_rcControl.top, Pos2Pixel(m_nPos-1), m_nHeight,&dcMem, 0, 0);

			}

			// Only one bitmap for channel
		}
		else
		{
			DrawBitmap(pDC, m_rcControl.left, m_rcControl.top, m_nWidth, m_nHeight,	&dcMem, 0, 0);
		}

		dcMem.SelectBitmap( pbmTmp );
	}

	// Draw thumb
	if( m_bThumb)
	{
		if( m_bThumbActive && (m_nState & STATE_PUSHED))
			pbmTmp = dcMem.SelectBitmap(m_bmThumbActive.m_hBitmap); // Active thumb
		else
			pbmTmp = dcMem.SelectBitmap(m_bmThumb.m_hBitmap); // Normal thumb

		// Vertical slider
		if( m_bVertical )
		{
			DrawBitmap(
				pDC, m_rcControl.left+m_nMarginLeft, m_rcControl.top+Pos2Pixel(m_nPos) - m_nThumbHeight/2,
				m_nThumbWidth, m_nThumbHeight,
				&dcMem, 0, 0);
		} 
		else // Horizontal slider
		{
			DrawBitmap(
				pDC, m_rcControl.left+Pos2Pixel(m_nPos) - m_nThumbWidth/2, m_rcControl.top+m_nMarginTop,
				m_nThumbWidth, m_nThumbHeight,
				&dcMem, 0, 0);

		} // if horizontal

		dcMem.SelectBitmap( pbmTmp );

	} // if draw thumb

	dcMem.DeleteDC();

}